﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MultiGed2
{
 public partial class EventLog : UserControl
 {
  public EventLog()
  {
   InitializeComponent();
  }

  private enum EventSeverity
  {
   Info, Success, Warning, Fail
  }

  private object mutex = new object();

  private void LogMessage(string message, EventSeverity severity)
  {
   lock (mutex)
   {
    dgvLog.Rows.Add(new string[] {
     "", DateTime.Now.ToLongTimeString(), message
    });
    DataGridViewRow row = dgvLog.Rows[dgvLog.RowCount - 1];
    Color color = SystemColors.Window;
    switch (severity)
    {
     case EventSeverity.Success:
      color = Color.Green;
      break;
     case EventSeverity.Warning:
      color = Color.Yellow;
      break;
     case EventSeverity.Fail:
      color = Color.Red;
      break;
     case EventSeverity.Info:
      color = Color.DarkBlue;
      break;
     default:
      break;
    }
    row.Cells[0].Style.BackColor = color;
    dgvLog.FirstDisplayedScrollingRowIndex = dgvLog.RowCount - 1;
    dgvLog.ClearSelection();
   }
  }

  public void LogInfo(string message)
  {
   LogMessage(message, EventSeverity.Info);
  }

  public void LogSuccess(string message)
  {
   LogMessage(message, EventSeverity.Success);
  }

  public void LogWarning(string message)
  {
   LogMessage(message, EventSeverity.Warning);
  }

  public void LogError(string message)
  {
   LogMessage(message, EventSeverity.Fail);
  }

  private void removeAllToolStripMenuItem_Click(object sender, EventArgs e)
  {
   dgvLog.Rows.Clear();
  }
 }
}
